package cn.wolfcode.rbac.web.controller;

import cn.wolfcode.rbac.domain.Permission;
import cn.wolfcode.rbac.query.QueryObject;
import cn.wolfcode.rbac.service.IPermissionService;
import cn.wolfcode.rbac.util.PageData;
import cn.wolfcode.rbac.util.QueryConstanst;
import cn.wolfcode.rbac.util.R;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/api/permissions")
public class PermissionController {
    @Autowired
    private IPermissionService permissionService;
    @PostMapping("/load")
    public R load(){
        permissionService.load();
        return R.ok();
    }
    @GetMapping
    public R query(QueryObject qo){
        PageInfo pageInfo = permissionService.query(qo);
        return R.ok(new PageData(pageInfo));
    }
    @GetMapping(headers = QueryConstanst.CMD_LIST)
    public R list(){
        List<Permission> permissions = permissionService.listAll();
        return R.ok(permissions);
    }
}
